﻿
@{
    ViewBag.Title = "编辑发货单柜号";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}
@model IOA.MES.DataAccess.VModel.VDeliveryOrder

@section Contents{
    <style>
        .layui-form-item .layui-input-inline {
            width: 300px;
        }

        .red {
            color: red;
        }
    </style>
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-form" lay-filter="layuiadmin-app-form-list" style="padding: 20px 30px;">
        <div class="layui-form-item">
            <label class="layui-form-label" v-html="lang.Field.DeliveryNo">发货单号：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="barCode" value="@Model.DeliveryNo" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" v-html="lang.Field.CabinetNo">发货柜号：</label>
            <div class="layui-input-inline">
                <textarea id="txtCabinetNos" class="layui-textarea"></textarea>
            </div>
        </div>

        @if (Model.Status == IOA.MES.DataAccess.Enum.DeliveryStatus.New)
        {
            <div class="layui-form-item" style="text-align:center;padding-top: 20px;">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit"><i class="layui-icon">&#xe605;</i>保存</button>
            </div>
        }

    </div>
</script>

@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package,
                delivery: @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model))
            }
        });
        setTimeout(function () {
            initLayui();
        }, 50);

        function initLayui() {
            layui.use(['form', 'layer', 'index', 'laydate', 'upload'], function () {
                var layer = layui.layer,
                    upload = layui.upload,
                    form = layui.form;

                var cabinetNos = new Array();
                for (var i = 0; i < vm.$data.delivery.Cabinets.length; i++) {
                    cabinetNos.push(vm.$data.delivery.Cabinets[i].CabinetNo);
                }
                $("#txtCabinetNos").val(cabinetNos.join("\n"));

                form.on('submit(submit)', function (data) {
                    var loadId = layer.load();
                    $.ajax({
                        url: "/Plan/SaveDeliveryCabinets",
                        data: {
                            deliveryNo: vm.$data.delivery.DeliveryNo,
                            cabinetNos: $("#txtCabinetNos").val().trim().split('\n')
                        },
                        complete: function () {
                            layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            parent.layui.layer.msg("保存成功！", { icon: 6, time: 1000 });
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        }
                    });
                    return false;
                });
            });
        }
    </script>
}
